<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*
<span class='line'>  2</span>  * Timemap.js Copyright 2010 Nick Rabinowitz.
<span class='line'>  3</span>  * Licensed under the MIT License (see LICENSE.txt)
<span class='line'>  4</span>  */</span><span class="WHIT">
<span class='line'>  5</span> </span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>  6</span> </span><span class="COMM">/**
<span class='line'>  7</span>  * @fileOverview
<span class='line'>  8</span>  * XML Loader
<span class='line'>  9</span>  *
<span class='line'> 10</span>  * @author Nick Rabinowitz (www.nickrabinowitz.com)
<span class='line'> 11</span>  */</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 13</span> </span><span class="COMM">/*globals TimeMap */</span><span class="WHIT">
<span class='line'> 14</span> 
<span class='line'> 15</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 16</span>  * @class
<span class='line'> 17</span>  * This is a base loader class for XML files.
<span class='line'> 18</span>  *
<span class='line'> 19</span>  * @augments TimeMap.loaders.remote
<span class='line'> 20</span>  * @requires param.js
<span class='line'> 21</span>  *
<span class='line'> 22</span>  * @param {Object} options          All options for the loader
<span class='line'> 23</span>  * @param {String} options.url              URL of XML file to load (NB: must be local address)
<span class='line'> 24</span>  * @parem {String[]} [options.extraTags]    Array of names for extra tag elements to load
<span class='line'> 25</span>  * @param {Object} [options.tagMap]         Map of tagName:paramName pairs, if you want to load
<span class='line'> 26</span>  *                                          data into a differently-named elements
<span class='line'> 27</span>  * @param {mixed} [options[...]]            Other options (see {@link TimeMap.loaders.remote})
<span class='line'> 28</span>  * @return {TimeMap.loaders.remote} Remote loader configured for XML
<span class='line'> 29</span>  */</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="NAME">TimeMap.loaders.xml</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 31</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">loader</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">TimeMap.loaders.remote</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 32</span> </span><span class="WHIT">        </span><span class="NAME">tagMap</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.tagMap</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT">        </span><span class="NAME">extraTags</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.extraTags</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">        </span><span class="NAME">params</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">loader.params</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT">    </span><span class="COMM">/**
<span class='line'> 37</span>      * Load function for remote XML files.
<span class='line'> 38</span>      * @name TimeMap.loaders.xml#load
<span class='line'> 39</span>      * @function
<span class='line'> 40</span>      *
<span class='line'> 41</span>      * @param {TimeMapDataset} dataset  Dataset to load data into
<span class='line'> 42</span>      * @param {Function} callback       Function to call once data is loaded
<span class='line'> 43</span>      */</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">    </span><span class="NAME">loader.load</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dataset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">        </span><span class="COMM">// get loader callback name (allows cancellation)</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">        </span><span class="NAME">loader.callbackName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">loader.getCallbackName</span><span class="PUNC">(</span><span class="NAME">dataset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">        </span><span class="COMM">// set the callback function</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">        </span><span class="COMM">// see http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">        </span><span class="NAME">loader.opts.dataType</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">  </span><span class="NAME">$.browser.msie</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">"text"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"xml"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">        </span><span class="NAME">loader.opts.success</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">xml</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">data</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">                </span><span class="NAME">xml</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">ActiveXObject</span><span class="PUNC">(</span><span class="STRN">"Microsoft.XMLDOM"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">                </span><span class="NAME">xml.async</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">                </span><span class="NAME">xml.loadXML</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">                </span><span class="NAME">xml</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">            </span><span class="NAME">TimeMap.loaders.cb</span><span class="PUNC">[</span><span class="NAME">loader.callbackName</span><span class="PUNC">]</span><span class="PUNC">(</span><span class="NAME">xml</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">        </span><span class="COMM">// download remote data</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">        </span><span class="NAME">$.ajax</span><span class="PUNC">(</span><span class="NAME">loader.opts</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">    
<span class='line'> 65</span>     </span><span class="COMM">/**
<span class='line'> 66</span>      * Additional parameters to load
<span class='line'> 67</span>      * @name TimeMap.loaders.xml#extraParams
<span class='line'> 68</span>      * @type TimeMap.params.OptionParam[]
<span class='line'> 69</span>      */</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">    </span><span class="NAME">loader.extraParams</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">    </span><span class="COMM">// set up extra params</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">    </span><span class="NAME">extraTags.forEach</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">tagName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">        </span><span class="NAME">loader.extraParams.push</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">            </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">TimeMap.params.OptionParam</span><span class="PUNC">(</span><span class="NAME">tagMap</span><span class="PUNC">[</span><span class="NAME">tagName</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">tagName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">                </span><span class="NAME">sourceName</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">tagName</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">        </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">    </span><span class="COMM">/**
<span class='line'> 82</span>      * Parse any extra tags that have been specified into the config object
<span class='line'> 83</span>      * @name TimeMap.loaders.xml#parseExtra
<span class='line'> 84</span>      * @function
<span class='line'> 85</span>      *
<span class='line'> 86</span>      * @param {Object} config       Config object to modify
<span class='line'> 87</span>      * @param {XML NodeList} node   Parent node to look for tags in
<span class='line'> 88</span>      */</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">    </span><span class="NAME">loader.parseExtra</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">config</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">node</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">        </span><span class="NAME">loader.extraParams.forEach</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">ep</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">            </span><span class="NAME">ep.setConfigXML</span><span class="PUNC">(</span><span class="NAME">config</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">node</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">        </span><span class="NAME">node</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">loader</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 98</span> </span></pre></body></html>